package com.PAT.practice01;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: zjz
 * @Date: 2021/11/15/17:17
 * @Description:输入  6 2
 *              1 2 3 4 5 6
 *              输出
 *              5 6 1 2 3 4
 * @Target:数组元素循环右移问题
 */
public class 数组元素循环右移问题 {
    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);
        int len = input.nextInt();
        int n = input.nextInt();

        int[] Array = new int[len];
        for (int i = 0; i < len; i++) {
            Array[i] = input.nextInt();
        }

        for (int i : getArrayRemove1(n, Array)) {
            System.out.print(i+" ");
        }


    }

     /*
     * 输入  6 2
     *  1 2 3 4 5 6
     *  输出
     *  5 6 1 2 3 4
     *
     *
     * */

    public static int[] getArrayRemove1(int n,int[] arr){
        int len = arr.length;
        int l = len-1;

        for (int k = 0; k < n; k++) {
            while(l>0){
                swap(arr,l,--l);
            }
            l=len-1;

        }

        return arr;
    }










    /*
    * 输入  6 2
     *  1 2 3 4 5 6
     *  输出
     *   3 4 5 6 1 2
    *
    *
    * */
    public static int[] getArrayRemove(int n,int[] arr){
        int l = 0;
        int len = arr.length;
        for (int k = 0; k < n; k++) {
            while(l<len-1){
                swap(arr,l,++l);
            }
            l=0;

        }

        return arr;
    }



    public static void swap(int arr[],int x,int y){
        int temp = arr[x];
        arr[x] = arr[y];
        arr[y] = temp;
    }
}
